/**********************************************************************************************************************
 *
 * Project:    mGameEngine
 * File:       Keyboard.h
 * Author:     karooolek
 * Created on: 2009-01-05
 *
 **********************************************************************************************************************/

#ifndef KEYBOARD_H_
#define KEYBOARD_H_

#include "keycode.h"
#include "keyboardlistener.h"
#include "../common.h"

namespace mGameEngine
{

// Application prototype
namespace System
{
    class Application;
}

namespace Input
{

/**
 * Keyboard input control.
 * It catches keyboard events and sends them to registered listeners.
 */
class Keyboard
{
private:
    // GLUT callbacks
    friend class System::Application;
    static void _glutKeyboardFunc(uint8 key, int, int);
    static void _glutKeyboardUpFunc(uint8 key, int, int);
    static void _glutKeyboardSpecialFunc(int key, int, int);
    static void _glutKeyboardSpecialUpFunc(int key, int, int);

    /**
     * Keys map
     */
    static uint8 _keys[512];

    /**
     * Registered listeners
     */
    static List<KeyboardListener *> _listeners;

    /**
     * Private constructor
     */
    Keyboard();

public:
    /**
     * Check if key is pressed down.
     * @param key key code
     * @return true if key is pressed down, false otherwise
     */
    static bool isKeyDown(KeyCode key);

    /**
     * Get any key that is pressed down.
     * @return pressed key code or KEY_CODE_NONE
     */
    static KeyCode getAnyKeyDown();

    /**
     * Register new keyboard listener.
     * @param listener keyboard listener
     */
    static void addListener(KeyboardListener *listener);

    /**
     * Unregister keyboard listener.
     * @param listener keyboard listener
     */
    static void removeListener(KeyboardListener *listener);
};

}
}

#endif // KEYBOARD_H_
